package com.example.spring.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Direct Exchange配置类
 * 一个队列绑定到交换机上，要求该消息与一个特定的路由键完全匹配，这是一个完整的匹配。
 */
@Configuration
public class RabbitMqDirectConfig {

    @Bean
    public Queue queueA() {
        return new Queue("direct-queue1");
    }

    @Bean
    public Queue queueB() {
        return new Queue("direct-queue2");
    }

    @Bean
    DirectExchange directExchange() {
        return new DirectExchange("directExchange");
    }

    @Bean
    Binding bindingExchangeMsg(Queue queueA, DirectExchange exchange) {
        return BindingBuilder.bind(queueA).to(exchange).with("direct.msg1");
    }

    @Bean
    Binding bindingExchangeMsg2(Queue queueB, DirectExchange exchange) {
        return BindingBuilder.bind(queueB).to(exchange).with("direct.msg2");
    }


}
